#!/bin/bash
#SBATCH --spread-job
# Copyright (c) 2023 Presto Labs Pte. Ltd.
set -ex

if [ -z ${SLURM_JOB_ID} ]; then
  (>&2 echo "ERROR: run this script on slurm.")
  exit 1
fi

cd /remote/iosg/home-8/bot-hft/jenkins/workspace/coin2_feed_dumper/coin/python
NUM_PARALLEL="$((${SLURM_NTASKS} + 30))"
parallel -j "${NUM_PARALLEL}" --delay "{{job_submit_period}}" --joblog feed-dumper.log <<EOF
{% for trading_date in settings.keys() -%}
{% for machine in settings[trading_date].keys() -%}
{% for mea in settings[trading_date][machine].keys() -%}
{% for recipe in settings[trading_date][machine][mea].keys() -%}
{%- set mear = "{}.{}".format(mea, recipe) -%}
{% for group in settings[trading_date][machine][mea][recipe].keys() -%}
{% for symbol in settings[trading_date][machine][mea][recipe][group] -%}
srun -n1 -l --mem-per-cpu=1G --exclusive bash coin2/support/feed_dumper/oriocat_dump_single_file.sh "{{trading_date}}" "{{machine}}" "{{mear}}" "{{symbol}}"
{% endfor -%}
{% endfor -%}
{% endfor -%}
{% endfor -%}
{% endfor -%}
{% endfor -%}
EOF
